/**
 * 
 */
package kernel_gui.gui.extended;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.List;

import common.entities.persistent.User;



/**
 * @author Yoyo
 *
 */
public class EMainMenuFrame extends kernel_gui.gui.generic.graphic.MainMenuFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6320407771042631529L;


	public EMainMenuFrame(){
		if(!kernel.isAdministrator()){
			ControlPanelButton.setEnabled(false);
			ControlPanelButton.setToolTipText("<html>Use must logon as administrator to<br>access this feature</html>");
		}
		setExecuteOnCancel(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				Component components[] = MainPanel.getComponents();
				for (Component c : components) {
					c.setEnabled(true);
				}
			}
		});
		
		setExecuteBeforeLongRequest(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				Component components[] = MainPanel.getComponents();
				for (Component c : components) {
					c.setEnabled(false);
				}
				
			}
		});
	}
	
	@Override
	protected void PlayGameButtonActionPerformed(ActionEvent evt) {
    	int requestID = executeBeforeLongRequest(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				boolean ans = (Boolean) answer;
				if(ans){
					EMainMenuFrame.this.openAnotherFrame(EPlayGameFrame.class, true);
				}
				
			}
		});
    	 
		kernel.startGame(requestID);
	}


	@Override
	protected void HallOfFameButtonActionPerformed(ActionEvent evt) {
    	int requestID = executeBeforeLongRequest(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				@SuppressWarnings("unchecked")
				List<User> topUsers = (List<User>) answer;
				new EHallOfFame(topUsers).setVisible(true);
				EMainMenuFrame.this.setVisible(false);
				EMainMenuFrame.this.dispose();
				
			}
		});
    	 
		kernel.hallOfFame(15, requestID);		
	}


	@Override
	protected void MyProfileButtonActionPerformed(ActionEvent evt) {
		openAnotherFrame(EMyProfile.class, true);
		
	}


	@Override
	protected void ControlPanelButtonActionPerformed(ActionEvent evt) {
		EMainMenuFrame.this.openAnotherFrame(EControlPanelMenuFrame.class, true);
	}


	@Override
	protected void LogoutButtonActionPerformed(ActionEvent evt) {
    	int requestID = executeBeforeLongRequest(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				boolean ans = (Boolean) answer;
				if(ans){
					EMainMenuFrame.this.openAnotherFrame(ELoginFrame.class, true);
				}
				
			}
		});
    	 
		kernel.logOut(requestID);
		
	}


	@Override
	protected void ExitButtonActionPerformed(ActionEvent evt) {
    	int requestID = executeBeforeLongRequest(null);
    	 
		kernel.exitMillioner(requestID);
		
	}



	@Override
	protected void AboutButtonActionPerformed(ActionEvent evt) {
		EMainMenuFrame.this.openAnotherFrame(EAboutForm.class, true);		
	}

	@Override
	protected void setWindowComponentsWhenCalledFromAnotherFrame() {
		/*not needed*/
		
	}




}
